package org.javaforever.gatescore.reports;

import java.util.List;

import org.javaforever.gatescore.core.FrontDomain;
import org.javaforever.gatescore.core.FrontField;
import org.javaforever.gatescore.core.ValidateInfo;
import org.javaforever.gatescore.core.WriteableUtil;

public class EChartsReport extends ReportComb{
	protected EchartsReportLayout eLayout = new EchartsReportLayout();
	protected FrontDomain reportDomain;
	protected List<FrontField> xAxisFields;
	protected FrontField yName;
	
	public EChartsReport() {
		super();
	}
	
	public EChartsReport(FrontDomain reportDomain,List<FrontField> xAxisFields,FrontField yName) throws Exception{
		super();
		this.standardName = "EchartsReport"+reportDomain.getCapFirstDomainName()+yName.getCapFirstFieldName();
		this.label = reportDomain.getText()+ yName.getText() +"Echarts图表";
		if ("english".equalsIgnoreCase(reportDomain.getLanguage())) {
			this.label ="Echarts report for"+reportDomain.getText();
		}
		this.reportDomain = reportDomain;
		this.xAxisFields = xAxisFields;
		this.yName = yName;
		
		this.domains.add(this.reportDomain);
		
		eLayout.setReportDomain(this.reportDomain);
		eLayout.setxAxisFields(this.xAxisFields);
		eLayout.setyName(this.yName);
		eLayout.parse();
	}

	@Override
	public void generateCombFiles(String targetFolderPath) throws Exception {
		String relativeFolder = "src/views/pages/";
		WriteableUtil.writeToFile(targetFolderPath + "/"+relativeFolder+this.standardName.toLowerCase()+".vue", this.eLayout.generateStatements().getContent());
	}

	@Override
	public void generateCombFromDomians() throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public ValidateInfo validateDomains() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public boolean validateVerbs() throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean validateLayouts() throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	public FrontDomain getReportDomain() {
		return reportDomain;
	}

	public void setReportDomain(FrontDomain reportDomain) {
		this.reportDomain = reportDomain;
	}
	
	@Override
	public String getDomainNamesStr() {
		return this.reportDomain.getStandardName();
	}
	
	public String getxAxisFieldsNames() {
		if (this.xAxisFields==null||this.xAxisFields.size()==0) return "";
		StringBuilder sb = new StringBuilder();
		for (FrontField f:this.xAxisFields) {
			sb.append(f.getFieldName()).append(",");
		}
		String result = sb.toString();
		if (result.endsWith(",")) result = result.substring(0,result.lastIndexOf(","));
		return result;
	}
	public EchartsReportLayout geteLayout() {
		return eLayout;
	}

	public void seteLayout(EchartsReportLayout eLayout) {
		this.eLayout = eLayout;
	}

	public List<FrontField> getxAxisFields() {
		return xAxisFields;
	}

	public void setxAxisFields(List<FrontField> xAxisFields) {
		this.xAxisFields = xAxisFields;
	}

	public FrontField getyName() {
		return yName;
	}

	public void setyName(FrontField yName) {
		this.yName = yName;
	}
}
